package web.encriptacion;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import utils.Encriptador;

public class EncriptacionHome extends WebPage{
	private static final long serialVersionUID = 1L;
	private String texto;

	public EncriptacionHome() {
		Form<Void> form = new Form<Void>("form");
		texto = "";
		add(form.add(
			texto(),
			botonSiguiente()
		));
	}

	private Component texto() {
		IModel<String> modelo = new PropertyModel<String>(this, "texto");
		return new TextField<String>("texto", modelo);
	}

	private Component botonSiguiente() {
		return new AjaxSubmitLink("botonSiguiente") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				PageParameters parametros = new PageParameters();
				parametros.add("documento", Encriptador.get().encriptar(texto));
				this.setResponsePage(EncriptacionLink.class, parametros);
			}
			
			@Override
			protected void onError(AjaxRequestTarget target, Form<?> form) {}
		};
	}

	public void setTexto(String texto) {
		this.texto = texto;
	}

	public String getTexto() {
		return texto;
	}
}
